﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OpGen.Extensions.Security;

namespace OpGen.Extensions.Runtime.Client
{
    internal class ClientMessageTargetContainer<TMessage> : MethodTargetAuthentication,  IClientMessageTargetContainer
    {
        private ClientMessageTargetDelegate<TMessage> _target;
        private int _opCode;

        public ClientMessageTargetContainer(ClientMessageTargetDelegate<TMessage> target, int opCode, MethodAuthenticationTypes authentication)
        {
            _target = target;
            _opCode = opCode;
            base.Authentication = authentication;
        }

        public int OpCode
        {
            get { return _opCode; }
        }

        public ClientMessageTargetDelegate<TMessage> Target
        {
            get { return _target; }
        }

        public void Invoke(byte[] data )
        {
            var message = (TMessage)Activator.CreateInstance(typeof(TMessage), new object[] { data });
            _target.Invoke(message);
        }
    }
}
